home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.03 Mar 90 / Æesthete source / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-06  |  1.6 KB  |  68 lines  |  [TEXT/KAHL]

  1. /*.h2 Aesthete™ */
  2. /*.fo ©1989 David Dunham */
  3. /*
  4. Install the DetachResource patch
  5. */
  6.  
  7. #define global
  8. #include "aesthete.h"
  9. #include <pascal.h>
  10.  
  11. void main() {
  12.     Handle    handle;
  13.     Handle    sicn, creators;
  14.  
  15. asm {
  16.     btst    #0,0x17B                    ; check KeyMap+7 — is [Shift] key down?
  17.     bne        @noInstall                    ; yes — don’t install patch
  18. }
  19.     handle = GetResource('INIT',0);
  20.     DetachResource(handle);                /* Detach ourselves */
  21.     handle = GetResource('SHOW',0);        /* Get a handle to the PROC */
  22.     if (handle != 0L) {                    /* Loaded OK */
  23.         HLock(handle);                    /* Hold down the PROC */
  24.         CallPascal(128,-1,*handle);        /* ShowICON() */
  25.         HUnlock(handle);                /* Let it float in the heap again */
  26.     }
  27. asm {
  28.     bra        @around
  29.     dc.l    0                        ; for oldTrap
  30.     dc.l    0                        ; for creators handle
  31.     dc.l    0                        ; for sicn handle
  32. #define oldTrap        -12
  33. #define oCreators    -8
  34. #define oSicn        -4
  35. myPatch:
  36.     lea        @myPatch,A0
  37.     move.l    oCreators(A0),-(SP)
  38.     move.l    oSicn(A0),-(SP)
  39.     move.l    12(SP),A0                ; original parameter to _DetachResource
  40.     move.l    A0,-(SP)
  41.     jsr        aesthetize                ; aesthetize(rsrc,sicn,creators)
  42.     add.l    #12,SP
  43.     lea        @myPatch,A0
  44.     move.l    oldTrap(A0),A0
  45.     jmp        (A0)                    ; pass the call to original _DetachResource
  46.     _Debugger                        ; should never get here!
  47. }
  48. asm {
  49. around:
  50. }
  51.     sicn = double_SICN();            /* Get double-size sicns */
  52.     creators = GetResource('SIG#',0);
  53.     DetachResource(creators);
  54. asm {
  55.     move.w    #0xA992,D0
  56.     _GetTrapAddress
  57.     lea        @myPatch,A1
  58.     move.l    A0,oldTrap(A1)            ; save original trap address
  59.     lea        @myPatch,A0
  60.     move.w    #0xA992,D0
  61.     _SetTrapAddress                    ; install our patch
  62.     lea        @myPatch,A0
  63.     move.l    sicn,oSicn(A0)            ; stash it
  64.     move.l    creators,oCreators(A0)
  65. noInstall:
  66. }
  67. }
  68.